/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* vim:set et sts=4: */
/* IBust - IBus with Traditional interface
 * Copyright(c) 2013 Daniel Sun
 * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
 * Copyright (C) 2008-2010 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#if !defined (__IBUST_H_INSIDE__) && !defined (IBUST_COMPILATION)
#error "Only <ibust.h> can be included directly"
#endif

/**
 * SECTION: ibusttext
 * @short_description: Text with decorating information.
 * @see_also: #IBustAttribute
 *
 * An IBustText is the main text object in IBust.
 * The text is decorated according to associated IBustAttribute,
 * e.g. the foreground/background color, underline, and
 * applied scope.
 */

#ifndef __IBUST_TEXT_H_
#define __IBUST_TEXT_H_

#include "ibustserializable.h"
#include "ibustattrlist.h"

/*
 * Type macros.
 */
/* define IBustText macros */
#define IBUST_TYPE_TEXT             \
    (ibust_text_get_type ())
#define IBUST_TEXT(obj)             \
    (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUST_TYPE_TEXT, IBustText))
#define IBUST_TEXT_CLASS(klass)     \
    (G_TYPE_CHECK_CLASS_CAST ((klass), IBUST_TYPE_TEXT, IBustTextClass))
#define IBUST_IS_TEXT(obj)          \
    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUST_TYPE_TEXT))
#define IBUST_IS_TEXT_CLASS(klass)  \
    (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUST_TYPE_TEXT))
#define IBUST_TEXT_GET_CLASS(obj)   \
    (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUST_TYPE_TEXT, IBustTextClass))

G_BEGIN_DECLS

typedef struct _IBustText IBustText;
typedef struct _IBustTextClass IBustTextClass;

/**
 * IBustText:
 * @is_static: Whether @text is static, i.e., no need and will not be freed. Only TRUE if IBustText is newed from ibust_text_new_from_static_string().
 * @text: The string content of IBustText in UTF-8.
 * @attrs: Associated IBustAttributes.
 *
 * A text object in IBust.
 */
struct _IBustText {
    IBustSerializable parent;

    /* members */
    /*< public >*/
    gboolean is_static;
    gchar  *text;
    IBustAttrList *attrs;
};

struct _IBustTextClass {
    IBustSerializableClass parent;
};

GType            ibust_text_get_type                 (void);

/**
 * ibust_text_new_from_string:
 * @str: An text string to be set.
 * @returns: A newly allocated IBustText.
 *
 * New an IBustText from a string.
 *
 * @str will be duplicated in IBustText, so feel free to free @str after this function.
 */
IBustText        *ibust_text_new_from_string          (const gchar    *str);

/**
 * ibust_text_new_from_ucs4:
 * @str: An text string to be set.
 * @returns: A newly allocated IBustText.
 *
 * New an IBustText from an UCS-4 encoded string.
 *
 * @str will be duplicated in IBustText, so feel free to free @str after this function.
 */
IBustText        *ibust_text_new_from_ucs4            (const gunichar *str);

/**
 * ibust_text_new_from_static_string: (skip)
 * @str: An text string to be set.
 * @returns: A newly allocated IBustText.
 *
 * New an IBustText from a static string.
 *
 * Since @str is a static string which won't be freed.
 * This function will NOT duplicate @str.
 */
IBustText        *ibust_text_new_from_static_string   (const gchar    *str);

/**
 * ibust_text_new_from_printf:
 * @fmt: printf format string.
 * @...: arguments for @fmt.
 * @returns: A newly allocated IBustText.
 *
 * New an IBustText from a printf expression.
 *
 * The result of printf expression is stored in the new IBustText instance.
 */
IBustText        *ibust_text_new_from_printf          (const gchar    *fmt,
                                                     ...) G_GNUC_PRINTF (1, 2);

/**
 * ibust_text_new_from_unichar:
 * @c: A single UCS4-encoded character.
 * @returns: A newly allocated IBustText.
 *
 * New an IBustText from a single UCS4-encoded character.
 */
IBustText        *ibust_text_new_from_unichar         (gunichar        c);

/**
 * ibust_text_append_attribute:
 * @text: an IBustText
 * @type: IBustAttributeType for @text.
 * @value: Value for the type.
 * @start_index: The starting index, inclusive.
 * @end_index: The ending index, exclusive.
 *
 * Append an IBustAttribute for IBustText.
 */
void             ibust_text_append_attribute         (IBustText       *text,
                                                     guint           type,
                                                     guint           value,
                                                     guint           start_index,
                                                     gint            end_index);
/**
 * ibust_text_get_length:
 * @text: An IBustText.
 * @returns: Number of character in @text, not counted by bytes.
 *
 * Return number of characters in an IBustText.
 * This function is based on g_utf8_strlen(), so unlike strlen(),
 * it does not count by bytes but characters instead.
 */
guint            ibust_text_get_length               (IBustText       *text);

/**
 * ibust_text_get_is_static: (skip)
 * @text: An IBustText.
 * @returns: the is_static in @text.
 *
 * Return the is_static in an IBustText.
 */
gboolean         ibust_text_get_is_static            (IBustText       *text);

/**
 * ibust_text_get_text:
 * @text: An IBustText.
 * @returns: the text in @text.
 *
 * Return the text in an IBustText. Should not be freed.
 */
const gchar *    ibust_text_get_text                 (IBustText       *text);

/**
 * ibust_text_get_attributes:
 * @text: An IBustText.
 * @returns: (transfer none): the attrs in @text.
 *
 * Return the attributes in an IBustText. Should not be freed.
 */
IBustAttrList *   ibust_text_get_attributes           (IBustText       *text);

/**
 * ibust_text_set_attributes:
 * @text: An IBustText.
 * @attrs: An IBustAttrList
 */
void             ibust_text_set_attributes           (IBustText       *text,
                                                     IBustAttrList   *attrs);


G_END_DECLS
#endif

